﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace PaperManager
{
    public partial class AddForm : Form
    {
        public MainForm paForm;
        public bool mode=true;
        public AddForm()
        {
            InitializeComponent();
        }

        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (mode == true)
            {
                MyContainer.Itm tmp;
                tmp.Title = tbxTitle.Text;
                tmp.Author = tbxAuthor.Text;
                tmp.KeyWords = tbxKeyWords.Text;
                tmp.Abstract = tbxAbstract.Text;
                //填充ArrayList paperAl
                paForm.paperAL.add(tmp);
                //获得AL的当前索引
                int ALidx = paForm.paperAL.getCount() - 1;
                //在gridview中显示
                paForm.grdPaper.Rows.Add();
                //获得GD的当前行索引
                int curR = paForm.grdPaper.Rows.Count - 2;
                DataGridViewTextBoxCell celTitle = new DataGridViewTextBoxCell();
                celTitle.Value = paForm.paperAL.get(ALidx).Title;
                paForm.grdPaper[0, curR] = celTitle;
                DataGridViewTextBoxCell celAuthor = new DataGridViewTextBoxCell();
                celAuthor.Value = paForm.paperAL.get(ALidx).Author;
                paForm.grdPaper[1, curR] = celAuthor;
                DataGridViewTextBoxCell celKeyWords = new DataGridViewTextBoxCell();
                celKeyWords.Value = paForm.paperAL.get(ALidx).KeyWords;
                paForm.grdPaper[2, curR] = celKeyWords;
                DataGridViewTextBoxCell celAbstract = new DataGridViewTextBoxCell();
                celAbstract.Value = paForm.paperAL.get(ALidx).Abstract;
                paForm.grdPaper[3, curR] = celAbstract;
            }
            else
            {
                int idx = paForm.grdPaper.CurrentRow.Index;
                MyContainer.Itm tmp;
                tmp.Title = tbxTitle.Text;
                tmp.Author = tbxAuthor.Text;
                tmp.KeyWords = tbxKeyWords.Text;
                tmp.Abstract = tbxAbstract.Text;
                //修改arraylist
                paForm.paperAL.set(idx, tmp);
                //修改grdview
                paForm.grdPaper.CurrentRow.Cells[0].Value = tmp.Title;
                paForm.grdPaper.CurrentRow.Cells[1].Value = tmp.Author;
                paForm.grdPaper.CurrentRow.Cells[2].Value = tmp.KeyWords;
                paForm.grdPaper.CurrentRow.Cells[3].Value = tmp.Abstract;
            }
        }
    }
}
